package com.choudou5.web;

import com.choudou5.bo.R;
import com.choudou5.service.CommonService;
import com.choudou5.utils.JsonUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("/test")
public class TestController extends BaseController {

	@Resource
	private CommonService commonService;

    @RequestMapping("hello")
    @ResponseBody
    public String hello(HttpServletRequest req){
        return JsonUtil.toStr(R.ok("hello world"));
    }

    @RequestMapping("add")
    @ResponseBody
    public String testAdd(HttpServletRequest req){
        String type = req.getParameter("type");
        if(type.equals("add")){
            commonService.add();
        }else if(type.equals("addTryCatch")){
            commonService.addTryCatch();
        }else if(type.equals("addTryCatchThrowable")){
            commonService.addTryCatchThrowable();
        }
    	return JsonUtil.toStr(R.ok());
    }

}
